package com.alan.dubbo.consume.config;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.AnnotationBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.PropertySources;
import org.springframework.core.io.InputStreamResource;

/**
 * Created by Alan on 2017/12/12.
 */
@Configuration
public class DubboConfig {


    @Value("${consumer.name}")
    private String consumerName;


    @Bean
    ApplicationConfig applicationconfig(@Value("${consumer.name}") String name ) {
        System.out.println(consumerName);
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName(name);
        return applicationConfig;
    }

    @Bean
    RegistryConfig registryconfig(@Value("${zk.address}") String _address) {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(_address);
        return registryConfig;
    }

    /**
     * 如注入此bean时要用static不然会使属性中的@Value 取不到值
     * @param 
     * @return
     */
    @Bean
    static AnnotationBean annotationBean() {
        AnnotationBean annotationBean = new AnnotationBean();
        annotationBean.setPackage("com.alan.dubbo.consume");
        return annotationBean;
    }

    @Bean
    ConsumerConfig consumerConfig(@Value("${alan.service.version}") String _version) {
        ConsumerConfig consumer = new ConsumerConfig();
        consumer.setCheck(false);
        consumer.setVersion(_version);
        return consumer;
    }

}
